﻿using System;
using System.ComponentModel;
using System.Windows.Forms;
using ajayumi.Platform;
using ajayumi.Platform.WinForm.UserCtlPanel;

namespace ajayumi.Test.WinUI
{
    [ToolboxItem(true)]
    public partial class ListDemoPanel : UserCtlPanelListBase
    {
        BindingList<TestInfo> m_ModelCollection = null;

        public ListDemoPanel()
        {
            InitializeComponent();

            this.m_ModelCollection = new BindingList<TestInfo>();
            this.RunWorkerCompleted += (sender, e) =>
            {
                if (e.Error != null)
                {
                    MessageBox.Show(string.Format("{0} 进行异步处理时，出现异常。异常信息如下：\r\n{1}\r\n",
                        DateTime.Now, e.Error.Message));
                }
                else
                {
                    this.dataGridViewEx1.DataSource = this.m_ModelCollection;
                    this.PageButtonStatus();
                }
            };

            this.searchContainer1.Searcher = new TestSearcher();
            this.searchContainer1.SearchHandler = (queryWhere) =>
            {
                MessageBox.Show(queryWhere);
            };
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            this.RunWorkAsync();
            this.RunWorkAsync();
        }

         protected override void DoWork(DoWorkEventArgs arg)
        {
            PageList<TestInfo> pl = BizTest.Instance.GetPageList(
                new PageInfo(this.PageSize, this.PageIndex), string.Empty, string.Empty);
            this.PageIndex = pl.PageInfo.PageIndex;
            this.PageCount = pl.PageInfo.PageCount;
            this.TotalRecoder = pl.PageInfo.RecordCount;
            this.m_ModelCollection = new BindingList<TestInfo>(pl.List);            
        }

      

    }
}
